package com.luge.model;

import java.util.ArrayList;

import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.BaseAdapter;

import com.luge.model.view.KeyItemView;
import com.luge.utils.Helper;

public class KeyListAdapter extends BaseAdapter {
	private ArrayList<KeyItem> list;

	public KeyListAdapter(ArrayList<KeyItem> list) {
		this.list = list;
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			convertView = new KeyItemView(parent.getContext());
			int width = (int) (Helper.getDisplayWidth(parent.getContext()) / 4.1);
			AbsListView.LayoutParams layoutParams = new AbsListView.LayoutParams(
					width, width);
			convertView.setLayoutParams(layoutParams);
		}
		KeyItemView itemView = (KeyItemView) convertView;
		itemView.setInfo(list.get(position));
		return convertView;
	}

}
